<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>寻找节点</title>
    <style>
        .c1{
            color: red;
        }
        .c2{
            color: green;
        }
                
    </style>
</head>
<body>
    <ul id="ul1">
        <li class="c1">ul1-li1</li>
        <li class="c2">ul1-li2</li>
        <li class="c1">ul1-li3
            <ul id="ul2">
                <li class="c1">ul2-li1</li>
                <li class="c2">ul2-li2</li>
                <li class="c1">ul2-li3</li>
            </ul>
        </li>
    </ul>
    <script>
        const ul2 = document.getElementById("ul2");
        console.log(ul2);
        // CSS选择器查找
        const elems = ul2.querySelectorAll("li.c1");
        for (let elem of elems){console.log(elem);}
        const elem = ul2.querySelector("li.c1");
        console.log(elem);
        console.log(elem.closest("ul"));
    </script>
</body>
</html>